//
//  HelpObject.m
//  MobileLier
//
//  Created by caoshuaikun on 16/4/13.
//  Copyright © 2016年 com.Mobilizer.name. All rights reserved.
//

#import "HelpObject.h"
#import <objc/message.h>
#import <sys/utsname.h>
#import <SSKeychain.h>

static HelpObject *helper = nil;
@implementation HelpObject


+ (HelpObject *)manager{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        helper = [[HelpObject alloc]init];
    });
    return helper;
}

//获取本地小数据缓存
+ (NSString *)df:(NSString *)getDFMessge{

    NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
    return [user objectForKey:getDFMessge];
    
}



//lable动画
- (UILabel *)labelActionChenge:(NSString *)labelText myView:(UIView *)myView{
    
    UILabel *lable =[[UILabel alloc]init];
    lable.frame =CGRectMake(Width/2 - 125, Height - 150, 250, [self textHeightFromString:labelText width:250 fontSize:22 space:1]);
    lable.numberOfLines = 0;
    lable.clipsToBounds =YES;
    lable.layer.cornerRadius = 5;
    lable.font = [UIFont systemFontOfSize:15];
    lable.alpha =0.8;
    lable.text =labelText;
    lable.textAlignment =NSTextAlignmentCenter;
    lable.backgroundColor =[UIColor grayColor];
    lable.textColor = [UIColor whiteColor];
    [myView addSubview:lable];
    
    [UIView animateWithDuration:3.0 animations:^{
        lable.alpha =0;
    }completion:^(BOOL finished) {
        [lable removeFromSuperview];
    }];
    
    return lable;
    
}

//lable动画
- (UILabel *)labelActionChange:(NSString *)labelText myView:(UIView *)myView{
    
    UILabel *lable =[[UILabel alloc]init];
    lable.frame =CGRectMake(Width/2 - 125, Height/2, 250, [self textHeightFromString:labelText width:250 fontSize:22 space:1]);
    lable.numberOfLines = 0;
    lable.clipsToBounds =YES;
    lable.layer.cornerRadius = 5;
    lable.font = [UIFont systemFontOfSize:15];
    lable.alpha =0.8;
    lable.text =labelText;
    lable.textAlignment =NSTextAlignmentCenter;
    lable.backgroundColor =[UIColor grayColor];
    lable.textColor = [UIColor whiteColor];
    [myView addSubview:lable];
    
    [UIView animateWithDuration:3.0 animations:^{
        lable.alpha =0;
    }completion:^(BOOL finished) {
        [lable removeFromSuperview];
    }];
    
    return lable;
    
}

//获取字体gaodu 宽度
-(CGFloat)textHeightFromString:(NSString *)textStr width:(CGFloat)width fontSize:(CGFloat)size space:(CGFloat)space{
    
    NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle1 setLineSpacing:space];
    CGRect frame=[textStr boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin
                  |NSStringDrawingTruncatesLastVisibleLine
                  |NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:size],NSParagraphStyleAttributeName:paragraphStyle1} context:nil];
    
    return frame.size.height;
}

//获取文字尺寸
- (CGSize)textRectFromString:(NSString *)textStr size:(CGSize)size font:(float)textFont{
    CGSize frame = [textStr boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:textFont]} context:nil].size;
    return frame;
}

//文件压缩
- (UIImage *) scaleFromImage: (UIImage *) image toSize: (CGSize) size
{
    // 创建一个bitmap的context
    // 并把它设置成为当前正在使用的context
    UIGraphicsBeginImageContext(size);
    // 绘制改变大小的图片
    [image drawInRect:CGRectMake(0,0, size.width, size.height)];
    // 从当前context中创建一个改变大小后的图片
    UIImage* scaledImage =UIGraphicsGetImageFromCurrentImageContext();
    // 使当前的context出堆栈
    UIGraphicsEndImageContext();
    
    return scaledImage;
}

//图片转化为data data的length就是他的大小然后除上1024就是多少k了

+ (NSData *)chengeData:(UIImage *)image{
    
    NSData *data;
    if (UIImagePNGRepresentation(image) == nil) {
        //JPG图片
        data = UIImageJPEGRepresentation(image, 1);
    } else {
        //png图片
        data = UIImagePNGRepresentation(image);
    }
    
    return data;
}



//保持原来的长宽比，生成一个
- (UIImage *)thumbnailWithImageWithoutScale:(UIImage *)image size:(CGSize)asize
{
    UIImage *newimage;
    if (nil == image) {
        newimage = nil;
    }
    else{
        CGSize oldsize = image.size;
        CGRect rect;
        if (asize.width/asize.height > oldsize.width/oldsize.height) {
            rect.size.width = asize.width*oldsize.height/oldsize.width;
            // rect.size.height = asize.height*oldsize.height/oldsize.width;
            rect.size.height = asize.width*oldsize.height/oldsize.width;
            rect.origin.x = (asize.width - rect.size.width)/2;
            
            rect.origin.y = 0;
        }
        else{
            //rect.size.width = asize.width;
            rect.size.width = asize.height*oldsize.width/oldsize.height;
            rect.size.height = asize.height*oldsize.width/oldsize.height;
            rect.origin.x = 0;
            rect.origin.y = (asize.height - rect.size.height)/2;
            
        }
        UIGraphicsBeginImageContext(asize);
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]);
        UIRectFill(CGRectMake(0, 0, asize.width, asize.height));//clear background
        [image drawInRect:rect];
        newimage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    }
    return newimage;
}

//图片压缩宽度
+ (UIImage *) imageCompressForWidth:(UIImage *)sourceImage targetWidth:(CGFloat)defineWidth{
    UIImage *newImage = nil;
    CGSize imageSize = sourceImage.size;
    CGFloat width = imageSize.width;
    CGFloat height = imageSize.height;
    CGFloat targetWidth = defineWidth;
    CGFloat targetHeight = height / (width / targetWidth);
    CGSize size = CGSizeMake(targetWidth, targetHeight);
    CGFloat scaleFactor = 0.0;
    CGFloat scaledWidth = targetWidth;
    CGFloat scaledHeight = targetHeight;
    CGPoint thumbnailPoint = CGPointMake(0.0, 0.0);
    if(CGSizeEqualToSize(imageSize, size) == NO){
        CGFloat widthFactor = targetWidth / width;
        CGFloat heightFactor = targetHeight / height;
        if(widthFactor > heightFactor){
            scaleFactor = widthFactor;
        }
        else{
            scaleFactor = heightFactor;
        }
        scaledWidth = width * scaleFactor;
        scaledHeight = height * scaleFactor;
        if(widthFactor > heightFactor){
            thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5;
        }else if(widthFactor < heightFactor){
            thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5;
        }
    }
    UIGraphicsBeginImageContext(size);
    CGRect thumbnailRect = CGRectZero;
    thumbnailRect.origin = thumbnailPoint;
    thumbnailRect.size.width = scaledWidth;
    thumbnailRect.size.height = scaledHeight;
    
    [sourceImage drawInRect:thumbnailRect];
    
    newImage = UIGraphicsGetImageFromCurrentImageContext();
    if(newImage == nil){
        TBLog(@"scale image fail");
    }
    
    UIGraphicsEndImageContext();
    return newImage;
}

//压缩后的图片
+ (NSMutableArray *)imageCompressMutableArray:(NSMutableArray *)orinalImageMutableArray{

    NSMutableArray * imageMutableArray = [NSMutableArray array];
    
//    for (int i = 0; i < orinalImageMutableArray.count; i++) {
//        
//        NSData * origleImageData = orinalImageMutableArray[i];
//        
//        if (origleImageData.length / 1024 > 300) {
//            
//            UIImage * image = [UIImage imageWithData:orinalImageMutableArray[i]];
//            NSData * data = UIImageJPEGRepresentation([self imageCompressForWidth:image targetWidth:PictureWidth], 1.0);
//            [imageMutableArray addObject: data];
//            
//        }else{
//        
//            [imageMutableArray addObject: origleImageData];
//        
//        }
//        
//    }
    
    return imageMutableArray;

}

//获取当前是什么网络
- (int)getnate{
    
    //状态栏是由当前app控制的，首先获取当前app
    //type数字对应的网络状态依次是 ： 0 - 无网络 ; 1 - 2G ; 2 - 3G ; 3 - 4G ; 5 - WIFI
    UIApplication *app = [UIApplication sharedApplication];
    NSArray *children = [[[app valueForKeyPath:@"statusBar"] valueForKeyPath:@"foregroundView"] subviews];
    int type = 0;
    for (id child in children)
    {
        if ([child isKindOfClass:NSClassFromString(@"UIStatusBarDataNetworkItemView")]) {
            type = [[child valueForKeyPath:@"dataNetworkType"] intValue];
        }
    }
    
    return type;
}


- (UIImage *)compressImage:(UIImage *)image toMaxFileSize:(NSInteger)maxFileSize {
    
    CGFloat compression = 0.9f;
    CGFloat maxCompression = 0.1f;
    NSData *imageData = UIImageJPEGRepresentation(image, compression);
    while ([imageData length] > maxFileSize && compression > maxCompression) {
        compression -= 0.1;
        imageData = UIImageJPEGRepresentation(image, compression);
    }
    
    UIImage *compressedImage = [UIImage imageWithData:imageData];
    return compressedImage;
}


//数组转为字符串数组
+ (NSString *)arrayChengeToString:(NSMutableArray *)OriginalArray{
    
    NSData *arrayData = [NSJSONSerialization dataWithJSONObject:OriginalArray options:NSJSONWritingPrettyPrinted error:nil];
    NSString *arrayJsonString = [[NSString alloc] initWithData:arrayData encoding:NSUTF8StringEncoding];

    return arrayJsonString;
}

//根据url获取图片
+ (UIImage *)getUrlImage:(NSURL *)url{

    NSData * data = [NSData dataWithContentsOfURL:url];
    UIImage * image = [UIImage imageWithData:data];
    
    return image;
}
//判断字符串是不是空
+ (BOOL)isBlankString:(NSString *)string{
    
    if (string == nil) {
        
        return YES;
        
    }
    
    if (string == NULL) {
        
        return YES;
        
    }
    
    if ([string isKindOfClass:[NSNull class]]) {
        
        return YES;
        
    }
    
    if ([[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length]==0) {
        
        return YES;
        
    }
    
    return NO;
    
}

//完整判断方法
+ (BOOL)isNull:(id)object
{
    // 判断是否为空串
    if ([object isEqual:[NSNull null]]) {
        return YES;
    } else if ([object isKindOfClass:[NSNull class]]) {
        return YES;
    } else if (object==nil) {
        return YES;
    }
    
    return NO;
}

+ (NSString *)changeNull:(id)object {
    if ([self isNull:object]) {
        return @"";
    } else {
        return [NSString stringWithFormat:@"%@",object];
    }
}

+ (void)userDefaultsSet:(NSString *)key value:(NSString *)value {
    NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
    [user setObject:value forKey:key];
}

//对空串进行发消息会出现各种各样的崩溃，让人很无语，同理转换字符串
-(NSString*)convertNull:(id)object{
    
    // 转换空串
    
    if ([object isEqual:[NSNull null]]) {
        
        return @" ";
        
    } else if ([object isKindOfClass:[NSNull class]]) {
        
        return @" ";
    } else if (object==nil) {
        
        return @"无";
    }
    
    return object;
    
}

//图片压缩指定大小
+ (UIImage *)PhotoCompressedToSpecifiedSize:(UIImage *)orignalPicture{

    NSData * data = UIImageJPEGRepresentation(orignalPicture, 1.0);

    while (data.length / 1024 > 200) {
        
        UIImage * image = [UIImage imageWithData:data];
        
        data = UIImageJPEGRepresentation(image, 0.9);
        
    }
    
    return [UIImage imageWithData:data];
}



//判断两个数组元素是否相等(仅仅企划,shit,还要自己把头去掉)
+ (BOOL)judgeSameArray:(NSArray *)arrayOne WithArray:(NSArray *)arrayTwo {
    
    NSMutableArray *array1 = [NSMutableArray arrayWithArray:arrayOne];
    NSMutableArray *array2 = [NSMutableArray arrayWithArray:arrayTwo];
    
    [array1 sortUsingComparator:^NSComparisonResult(id  _Nonnull obj1, id  _Nonnull obj2) {
        return obj1 > obj2;
    }];
    
    [array2 sortUsingComparator:^NSComparisonResult(id  _Nonnull obj1, id  _Nonnull obj2) {
        return obj1 > obj2;
    }];
    
    BOOL isSame = NO;
    
    if (array2.count == array1.count) {
        isSame = YES;
        for (int i = 0; i < array1.count; i++) {
            NSString *ar2Str = array2[i];
            if ([ar2Str containsString:@"A."] || [ar2Str containsString:@"B."] || [ar2Str containsString:@"C."] ||[ar2Str containsString:@"D."] || [ar2Str containsString:@"E."] || [ar2Str containsString:@"F."]) {
                if (![array1[i] isEqualToString:[ar2Str substringFromIndex:2]]) {
                    isSame = NO;
                }
            } else {
                if (![array1[i] isEqualToString:ar2Str]) {
                    isSame = NO;
                }
            }
            
        }
        
    }
    
    return isSame;
}

// 正则判断手机号码地址格式
+ (BOOL)isMobileNumber:(NSString *)mobileNum {
    
    //    电信号段:133/153/180/181/189/177
    //    联通号段:130/131/132/155/156/185/186/145/176
    //    移动号段:134/135/136/137/138/139/150/151/152/157/158/159/182/183/184/187/188/147/178
    //    虚拟运营商:170
    
    NSString *MOBILE = @"^1(3[0-9]|4[57]|5[0-35-9]|8[0-9]|7[06-8])\\d{8}$";
    
    NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
    
    return [regextestmobile evaluateWithObject:mobileNum];
}


//截取字符串 3;3;3
+ (NSArray *)getStrFrom:(NSString *)text to:(NSString *)flag {
    NSMutableArray *array = [NSMutableArray array];
    NSRange range = [text rangeOfString:flag];
    NSString *str = [text substringToIndex:range.location];
    [array addObject:str];
    NSString *least = [text substringFromIndex:range.location+range.length];
    NSRange range2 = [least rangeOfString:flag];
    NSString *str2 = [least substringToIndex:range2.location];
    [array addObject:str2];
    NSString *str3 = [least substringFromIndex:range2.location+range2.length];
    [array addObject:str3];
    return array;
}

//存储本地数据
+ (void)saveMsg:(NSString *)msg key:(NSString *)key {
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    [user setObject:msg forKey:key];
}

//归档接档存储数据----
//写入沙盒
+ (void)writeToDocument:(id)file strPath:(NSString *)strPath{
    NSString * filePath = [self getDocumentFilePath:strPath];
    BOOL isSuccess = [NSKeyedArchiver archiveRootObject:file toFile:filePath];
    if (isSuccess) {
        NSLog(@"存储成功");
    }else {
        NSLog(@"存储失败");
    }
}

//读取沙盒内容
+ (id)getDocumentDicStrPath:(NSString *)strPath {
    NSString * filePath = [self getDocumentFilePath:strPath];
    id poiListDic = [NSKeyedUnarchiver unarchiveObjectWithFile:filePath];
    return poiListDic;
}

//document路径
+ (NSString *)getDocumentFilePath:(NSString *)strPath {
    NSString * path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
    NSString * filePath = [path stringByAppendingPathComponent:strPath];
    return filePath;
}

//汉字转拼音
- (NSString *) phonetic:(NSString*)sourceString {
    NSMutableString *source = [sourceString mutableCopy];
    CFStringTransform((__bridge CFMutableStringRef)source, NULL, kCFStringTransformMandarinLatin, NO);
    CFStringTransform((__bridge CFMutableStringRef)source, NULL, kCFStringTransformStripDiacritics, NO);
    return source;
}

+(NSString *)getUrlStringFromString:(NSString *)urlStr{
    NSString *outputStr = (__bridge NSString *)
    CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
                                            (__bridge CFStringRef)urlStr,
                                            NULL,
                                            (CFStringRef)@"!*'();:@&=+$,/?%#[]",
                                            kCFStringEncodingUTF8);
    return outputStr;
}



/**
 ** lineView:	   需要绘制成虚线的view
 ** lineLength:	 虚线的宽度
 ** lineSpacing:	虚线的间距
 ** lineColor:	  虚线的颜色
 **/
+ (void)drawDashLine:(UIView *)lineView lineLength:(int)lineLength lineSpacing:(int)lineSpacing lineColor:(UIColor *)lineColor
{
    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    [shapeLayer setBounds:lineView.bounds];
    [shapeLayer setPosition:CGPointMake(CGRectGetWidth(lineView.frame) / 2, CGRectGetHeight(lineView.frame))];
    [shapeLayer setFillColor:[UIColor clearColor].CGColor];
    //  设置虚线颜色为blackColor
    [shapeLayer setStrokeColor:lineColor.CGColor];
    //  设置虚线宽度
    [shapeLayer setLineWidth:CGRectGetHeight(lineView.frame)];
    [shapeLayer setLineJoin:kCALineJoinRound];
    //  设置线宽，线间距
    [shapeLayer setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:lineLength], [NSNumber numberWithInt:lineSpacing], nil]];
    //  设置路径
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, NULL, 0, 0);
    CGPathAddLineToPoint(path, NULL, CGRectGetWidth(lineView.frame), 0);
    [shapeLayer setPath:path];
    CGPathRelease(path);
    //  把绘制好的虚线添加上来
    [lineView.layer addSublayer:shapeLayer];
}

//正则判断身份证
- (BOOL)judgeIdentityStringValid:(NSString *)identityString {
    
    if (identityString.length != 18) return NO;
    // 正则表达式判断基本 身份证号是否满足格式
    NSString *regex2 = @"^(^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$)|(^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])((\\d{4})|\\d{3}[Xx])$)$";
    NSPredicate *identityStringPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex2];
    //如果通过该验证，说明身份证格式正确，但准确性还需计算
    if(![identityStringPredicate evaluateWithObject:identityString]) return NO;
    
    //** 开始进行校验 *//
    
    //将前17位加权因子保存在数组里
    NSArray *idCardWiArray = @[@"7", @"9", @"10", @"5", @"8", @"4", @"2", @"1", @"6", @"3", @"7", @"9", @"10", @"5", @"8", @"4", @"2"];
    
    //这是除以11后，可能产生的11位余数、验证码，也保存成数组
    NSArray *idCardYArray = @[@"1", @"0", @"10", @"9", @"8", @"7", @"6", @"5", @"4", @"3", @"2"];
    
    //用来保存前17位各自乖以加权因子后的总和
    NSInteger idCardWiSum = 0;
    for(int i = 0;i < 17;i++) {
        NSInteger subStrIndex = [[identityString substringWithRange:NSMakeRange(i, 1)] integerValue];
        NSInteger idCardWiIndex = [[idCardWiArray objectAtIndex:i] integerValue];
        idCardWiSum+= subStrIndex * idCardWiIndex;
    }
    
    //计算出校验码所在数组的位置
    NSInteger idCardMod=idCardWiSum%11;
    //得到最后一位身份证号码
    NSString *idCardLast= [identityString substringWithRange:NSMakeRange(17, 1)];
    //如果等于2，则说明校验码是10，身份证号码最后一位应该是X
    if(idCardMod==2) {
        if(![idCardLast isEqualToString:@"X"]||[idCardLast isEqualToString:@"x"]) {
            return NO;
        }
    }
    else{
        //用计算出的验证码与最后一位身份证号码匹配，如果一致，说明通过，否则是无效的身份证号码
        if(![idCardLast isEqualToString: [idCardYArray objectAtIndex:idCardMod]]) {
            return NO;
        }
    }
    return YES;
}


- (NSString*)iphoneType {
    
    //需要导入头文件：#import <sys/utsname.h>
    
    struct utsname systemInfo;
    
    uname(&systemInfo);
    
    NSString*platform = [NSString stringWithCString: systemInfo.machine encoding:NSASCIIStringEncoding];
    
    if([platform isEqualToString:@"iPhone1,1"])
        return@"iPhone 2G";
    
    if([platform isEqualToString:@"iPhone1,2"])
        return@"iPhone 3G";
    
    if([platform isEqualToString:@"iPhone2,1"]) return@"iPhone 3GS";
    
    if([platform isEqualToString:@"iPhone3,1"]) return@"iPhone 4";
    
    if([platform isEqualToString:@"iPhone3,2"]) return@"iPhone 4";
    
    if([platform isEqualToString:@"iPhone3,3"]) return@"iPhone 4";
    
    if([platform isEqualToString:@"iPhone4,1"]) return@"iPhone 4S";
    
    if([platform isEqualToString:@"iPhone5,1"]) return@"iPhone 5";
    
    if([platform isEqualToString:@"iPhone5,2"]) return@"iPhone 5";
    
    if([platform isEqualToString:@"iPhone5,3"]) return@"iPhone 5c";
    
    if([platform isEqualToString:@"iPhone5,4"]) return@"iPhone 5c";
    
    if([platform isEqualToString:@"iPhone6,1"]) return@"iPhone 5s";
    
    if([platform isEqualToString:@"iPhone6,2"]) return@"iPhone 5s";
    
    if([platform isEqualToString:@"iPhone7,1"]) return@"iPhone 6 Plus";
    
    if([platform isEqualToString:@"iPhone7,2"]) return@"iPhone 6";
    
    if([platform isEqualToString:@"iPhone8,1"]) return@"iPhone 6s";
    
    if([platform isEqualToString:@"iPhone8,2"]) return@"iPhone 6s Plus";
    
    if([platform isEqualToString:@"iPhone8,4"]) return@"iPhone SE";
    
    if([platform isEqualToString:@"iPhone9,1"]) return@"iPhone 7";
    
    if([platform isEqualToString:@"iPhone9,2"]) return@"iPhone 7 Plus";
    
    if([platform isEqualToString:@"iPhone10,1"]) return@"iPhone 8";
    
    if([platform isEqualToString:@"iPhone10,4"]) return@"iPhone 8";
    
    if([platform isEqualToString:@"iPhone10,2"]) return@"iPhone 8 Plus";
    
    if([platform isEqualToString:@"iPhone10,5"]) return@"iPhone 8 Plus";
    
    if([platform isEqualToString:@"iPhone10,3"]) return@"iPhone X";
    
    if([platform isEqualToString:@"iPhone10,6"]) return@"iPhone X";
    
    if([platform isEqualToString:@"iPod1,1"])
        return@"iPod Touch 1G";
    
    if([platform isEqualToString:@"iPod2,1"])
        return@"iPod Touch 2G";
    
    if([platform isEqualToString:@"iPod3,1"])
        return@"iPod Touch 3G";
    
    if([platform isEqualToString:@"iPod4,1"])
        return@"iPod Touch 4G";
    
    if([platform isEqualToString:@"iPod5,1"])
        return@"iPod Touch 5G";
    
    if([platform isEqualToString:@"iPad1,1"])
        return@"iPad 1G";
    
    if([platform isEqualToString:@"iPad2,1"])
        return@"iPad 2";
    
    if([platform isEqualToString:@"iPad2,2"])
        return@"iPad 2";
    
    if([platform isEqualToString:@"iPad2,3"])
        return@"iPad 2";
    
    if([platform isEqualToString:@"iPad2,4"])
        return@"iPad 2";
    
    if([platform isEqualToString:@"iPad2,5"])
        return@"iPad Mini 1G";
    
    if([platform isEqualToString:@"iPad2,6"])
        return@"iPad Mini 1G";
    
    if([platform isEqualToString:@"iPad2,7"])
        return@"iPad Mini 1G";
    
    if([platform isEqualToString:@"iPad3,1"])
        return@"iPad 3";
    
    if([platform isEqualToString:@"iPad3,2"])
        return@"iPad 3";
    
    if([platform isEqualToString:@"iPad3,3"])
        return@"iPad 3";
    
    if([platform isEqualToString:@"iPad3,4"])
        return@"iPad 4";
    
    if([platform isEqualToString:@"iPad3,5"])
        return@"iPad 4";
    
    if([platform isEqualToString:@"iPad3,6"])
        return@"iPad 4";
    
    if([platform isEqualToString:@"iPad4,1"])
        return@"iPad Air";
    
    if([platform isEqualToString:@"iPad4,2"])
        return@"iPad Air";
    
    if([platform isEqualToString:@"iPad4,3"])
        return@"iPad Air";
    
    if([platform isEqualToString:@"iPad4,4"])
        return@"iPad Mini 2G";
    
    if([platform isEqualToString:@"iPad4,5"])
        return@"iPad Mini 2G";
    
    if([platform isEqualToString:@"iPad4,6"])
        return@"iPad Mini 2G";
    
    if([platform isEqualToString:@"iPad4,7"])
        return@"iPad Mini 3";
    
    if([platform isEqualToString:@"iPad4,8"])
        return@"iPad Mini 3";
    
    if([platform isEqualToString:@"iPad4,9"])
        return@"iPad Mini 3";
    
    if([platform isEqualToString:@"iPad5,1"])
        return@"iPad Mini 4";
    
    if([platform isEqualToString:@"iPad5,2"])
        return@"iPad Mini 4";
    
    if([platform isEqualToString:@"iPad5,3"])
        return@"iPad Air 2";
    
    if([platform isEqualToString:@"iPad5,4"])
        return@"iPad Air 2";
    
    if([platform isEqualToString:@"iPad6,3"])
        return@"iPad Pro 9.7";
    
    if([platform isEqualToString:@"iPad6,4"])
        return@"iPad Pro 9.7";
    
    if([platform isEqualToString:@"iPad6,7"])
        return@"iPad Pro 12.9";
    
    if([platform isEqualToString:@"iPad6,8"])
        return@"iPad Pro 12.9";
    
    if([platform isEqualToString:@"i386"])
        return@"iPhone Simulator";
    
    if([platform isEqualToString:@"x86_64"])
        return@"iPhone Simulator";
    
    return platform;
    
}


+ (NSString *)getDeviceId
{
    
    NSString * currentDeviceUUIDStr = [SSKeychain passwordForService:@"UUID"account:@"uuid"];
    if (currentDeviceUUIDStr == nil || [currentDeviceUUIDStr isEqualToString:@""])
    {
        NSUUID * currentDeviceUUID  = [UIDevice currentDevice].identifierForVendor;
        currentDeviceUUIDStr = currentDeviceUUID.UUIDString;
        currentDeviceUUIDStr = [currentDeviceUUIDStr stringByReplacingOccurrencesOfString:@"-" withString:@""];
        currentDeviceUUIDStr = [currentDeviceUUIDStr lowercaseString];
        [SSKeychain setPassword: currentDeviceUUIDStr forService:@"UUID"account:@"uuid"];
    }
    return currentDeviceUUIDStr;
}



+ (UINavigationController *)getCurrentNav
{
    UITabBarController *tabbarVC = (UITabBarController *)[[UIApplication sharedApplication] delegate].window.rootViewController;
    
    //    UITabBarController *tabbarVC = (UITabBarController *)[[UIApplication sharedApplication] delegate].window.rootViewController;;
    UINavigationController *nav = (UINavigationController *)tabbarVC.selectedViewController;
    return nav;
}

+ (UIViewController *)getPresentedViewController
{
    UIViewController *appRootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
    UIViewController *topVC = appRootVC;
    if (topVC.presentedViewController) {
        topVC = topVC.presentedViewController;
    }
    return topVC;
}

//获取Window当前显示的ViewController
+ (UIViewController*)getCurrentViewController{
    //获得当前活动窗口的根视图
    UIViewController* vc = [UIApplication sharedApplication].keyWindow.rootViewController;
    while (1)
    {
        //根据不同的页面切换方式，逐步取得最上层的viewController
        if ([vc isKindOfClass:[UITabBarController class]]) {
            vc = ((UITabBarController*)vc).selectedViewController;
        }
        if ([vc isKindOfClass:[UINavigationController class]]) {
            vc = ((UINavigationController*)vc).visibleViewController;
        }
        if (vc.presentedViewController) {
            vc = vc.presentedViewController;
        }else{
            break;
        }
    }
    return vc;
}



+(UIImage *)colorizeImage:(UIImage *)baseImage withColor:(UIColor *)theColor {
    UIGraphicsBeginImageContext(baseImage.size);
    
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGRect area = CGRectMake(0, 0, baseImage.size.width, baseImage.size.height);
    
    CGContextScaleCTM(ctx, 1, -1);
    CGContextTranslateCTM(ctx, 0, -area.size.height);
    
    CGContextSaveGState(ctx);
    CGContextClipToMask(ctx, area, baseImage.CGImage);
    
    [theColor set];
    CGContextFillRect(ctx, area);
    
    CGContextRestoreGState(ctx);
    
    CGContextSetBlendMode(ctx, kCGBlendModeMultiply);
    
    CGContextDrawImage(ctx, area, baseImage.CGImage);
    
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    return newImage;
}


@end
